package com.heking.aoplib;

import android.content.Context;
import android.content.Intent;
import android.view.View;
import android.widget.Toast;

import com.zhoug.aop.interfaces.ILoginFilter;
import com.zhoug.widget.dialog.ButtonDialog;

/**全局登录验证,单例模式
 * @Author 35574
 * @Date 2020/7/1
 * @Description
 */
public class MyLoginFilter implements ILoginFilter {
    private static MyLoginFilter instance;

    private MyLoginFilter() {
    }

    public static MyLoginFilter getInstance() {
        if(instance==null){
            synchronized (MyLoginFilter.class){
                if(instance==null){
                    instance=new MyLoginFilter();
                }
            }
        }

        return instance;
    }

    @Override
    public boolean isLogin() {
        return false;
    }

    @Override
    public void showToast(String msg) {
        Toast.makeText(App.getApp(), msg, Toast.LENGTH_SHORT).show();
    }

    @Override
    public void showDialog(Context context, String msg) {
        if (context != null) {
            final ButtonDialog buttonDialog = new ButtonDialog(context, msg);
            buttonDialog.setCancelable(true);
            buttonDialog.setCanceledOnTouchOutside(true);
            buttonDialog.setOnclickListener1("取消", new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    buttonDialog.cancel();
                }
            });
            buttonDialog.setOnclickListener2("登录", new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    buttonDialog.cancel();
                    Intent intent = new Intent(context, LoginActivity.class);
                    context.startActivity(intent);

                }
            });
            buttonDialog.show();
        }
    }

    @Override
    public void toLogin(Context context) {
        if (context != null) {
            Intent intent = new Intent(context, LoginActivity.class);
            context.startActivity(intent);
        } else {
            Intent intent = new Intent(App.getApp(), LoginActivity.class);
            intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            App.getApp().startActivity(intent);

        }

    }


}
